
#ifndef STRINGUTIL_H
#define STRINGUTIL_H

#include <string>
#include <sstream>
#include <vector>

/** @class StringUtil
    A collection of simple methods for working with strings.
*/
class StringUtil
{
public:
    /** @typedef String
        Alternative name for std::string...
    */
    typedef std::string String;

    static const String WHITE_SPACE;    /** Defines the whitespace characters */
    static const String BLANK;          /** Empty string */

    /** @typedef StringVector
        An array of strings
    */
    typedef std::vector< String > StringVector;

public:

    /** Trim whitespace from either end of a string */
    static void Trim( String& str, bool removeLeft = true, bool removeRight = true );
    static void TrimLeft( String& str )     { Trim( str, true, false ); }
    static void TrimRight( String& str )    { Trim( str, false, true ); }

    /** Convert a value to a string */
    template< typename T >
    static String ToString( const T& val )
    {
        std::stringstream stream;
        stream << val;
        return stream.str();
    }

    /** Convert a string to upper case */
    static void ToUpper( String& str );

    /** Convert a string to lower case */
    static void ToLower( String& str );

    /** Find a substring within a string, returning the index of the substring.
        Returns -1 if the substring is not found.
    */
    static int Find( const String& src, const String& substr );
};

#endif  // STRINGUTIL_H
